import shelve
from config import database_path


def init_app():
    

    # 初始化表格字典
    with shelve.open(database_path) as db:
            db['tables_dict'] = {}


    # 初始化
    initial_data  = {
        'public_datas': [],
        'run_datas': [],
        'excel_task': {},
        'authentication': {'esn': None, 'end_time': 2023, 'status': False, '试用资格': True},
        'tables_dict': {}  # 表格字典
    }

    with shelve.open(database_path) as db:
        # db['authentication']={'esn':None ,'end_time':2023,'status':False,'试用资格':True}
        for data_key in initial_data :
            try:
                db[data_key]
            except KeyError:
                print(f'新建数据库{data_key},初始数据库为{str(initial_data [data_key])}')
                db[data_key] = initial_data [data_key]
